<template>
    <div>
        <el-row :gutter="20">
            <el-col :span="5">
                <el-card shadow="hover" class="mgb20" style="height:252px;">
                    <div class="user-info">
                        <img src="../../assets/img/img.jpg" class="user-avator" alt />
                        <div class="user-info-cont">
                            <div class="user-info-name">{{name}}</div>
                            <div>{{role}}</div>
                        </div>
                    </div>
                    <div class="user-info-list">
                        上次登录时间：
                        <span>2020-9-11</span>
                    </div>
                    <div class="user-info-list">
                        上次登录地点：
                        <span>重庆</span>
                    </div>
                </el-card>
                <el-card shadow="hover" style="height:252px;">
                    <div slot="header" class="clearfix">
                        <span>全市项目跟踪概览</span>
                    </div>
                    已完成<el-progress :percentage="71.3" color="#42b983"></el-progress>
                    待审核<el-progress :percentage="24.1" color="#f1e05a"></el-progress>
                    需修改<el-progress :percentage="13.7"></el-progress>
                    审核失败<el-progress :percentage="5.9" color="#f56c6c"></el-progress>
                </el-card>
            </el-col>
            <el-col :span="7">
                <el-card shadow="hover" style="height:525px;">
                    <div slot="header" class="clearfix">
                        <h2>柳州市年度/月度任务计划</h2>
                    </div>
                    <el-table :show-header="false" :data="todoList" style="width:100%;">
                        <el-table-column width="40">
                            <template slot-scope="scope">
                                <el-checkbox v-model="scope.row.status" @click="changeStatus(scope.row,scope.$index)"></el-checkbox>
                            </template>
                        </el-table-column>
                        <el-table-column>
                            <template slot-scope="scope">
                                <div
                                        class="todo-item"
                                        :class="{'todo-item-del': scope.row.status}"
                                >{{scope.row.title}}</div>
                            </template>
                        </el-table-column>
                        <el-table-column width="60">
                            <template>
                                <i class="el-icon-edit"></i>
                                <i class="el-icon-delete"></i>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-card>
            </el-col>
            <el-col :span="12">
                <el-card shadow="hover" style="height:525px;">
                    <div slot="header" class="clearfix">
                        <h2>柳州市政务公开</h2>
                    </div>
                    <el-carousel height="420px">
                        <el-carousel-item v-for="item in imgList" :key="item" height="420px" >
                            <h3><img :src="item" alt=""> </h3>
                        </el-carousel-item>
                    </el-carousel>
                </el-card>
            </el-col>
        </el-row>
        <el-row :gutter="20">
            <el-col :span="12">
                <el-card shadow="hover">
                    <schart ref="bar" class="schart" canvasId="bar" :options="options"></schart>
                </el-card>
            </el-col>
            <el-col :span="12">
                <el-card shadow="hover">
                    <schart ref="line" class="schart" canvasId="line" :options="options2"></schart>
                </el-card>
            </el-col>
        </el-row>
    </div>
</template>

<script>
import Schart from 'vue-schart';
import bus from '../common/bus';
export default {
    name: 'dashboard',
    data() {
        return {
            name: localStorage.getItem('ms_username'),
            imgList:[
                require('../../assets/img/images/a1.jpg'),
                require('../../assets/img/images/a2.png'),
                require('../../assets/img/images/a3.png'),
                require('../../assets/img/images/a4.jpg'),
                require('../../assets/img/images/a5.jpg')
            ],
            todoList: [

            ],
            data:
                [
                {
                    name: '2020/09/04',
                    value: 1083
                },
            ],
            options: {
                type: 'bar',
                title: {
                    text: '2020年1-6月份全市引进区外境内到位资金情况(亿元)'
                },
                xRorate: 25,
                labels: ['城中区', '柳北区', '鱼峰区', '柳南区', '柳江新区'],
                datasets: [
                    {
                        label: '年度任务',
                        data: [130, 109, 131, 128, 133]
                    },
                    {
                        label: '已完成',
                        data: [92.88, 50.88, 67.88, 32.75, 68.23]
                    }
                ]
            },
            options2: {
                type: 'line',
                title: {
                    text: '三企入桂近几个月投资金额(亿元)'
                },
                labels: ['1月', '2月', '3月', '4月', '5月','6月'],
                datasets: [
                    {
                        label: '央企入桂',
                        data: [34, 28, 27, 39, 30,40]
                    },
                    {
                        label: '民企入桂',
                        data: [45, 35, 50, 35, 60,47]
                    },
                    {
                        label: '湾企入桂',
                        data: [24, 28, 20, 35, 40,39]
                    }
                ]
            }
        };
    },
    components: {
        Schart
    },
    computed: {
        role() {
            return this.name === 'admin' ? '超级管理员' : '普通用户';
        }
    },
    mounted() {
        this.getPlanData();
    },
    /*created() {
        this.handleListener();
        this.changeDate();
    },

    activated() {
        this.handleListener();
    },
    deactivated() {
        window.removeEventListener('resize', this.renderChart);
        bus.$off('collapse', this.handleBus);
    },*/
    methods: {
        changeDate() {
            const now = new Date().getTime();
            this.data.forEach((item, index) => {
                const date = new Date(now - (6 - index) * 86400000);
                item.name = `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`;
            });
        },
       /* handleListener() {
            bus.$on('collapse', this.handleBus);
            // 调用renderChart方法对图表进行重新渲染
            window.addEventListener('resize', this.renderChart);
        },
        handleBus(msg) {
            setTimeout(() => {
                this.renderChart();
            }, 200);
        },
        renderChart() {
            this.$refs.bar.renderChart();
            this.$refs.line.renderChart();

        },*/
        getPlanData(){
            this.$axios.get('/plan/select',{}).then(resp=>{
                if (resp.data.success){
                    console.log(resp.data.data[0].planName+resp.data.data[0].planStatus)
                    for (let i = 0; i < resp.data.data.length; i++) {
                        var plan = {title:resp.data.data[i].planName,status:resp.data.data[i].planStatus};
                        this.todoList.push(plan);
                    }
                }
            })
        },
        changeStatus(row,index){
        }
    }
};
</script>


<style scoped>
.el-row {
    margin-bottom: 20px;
}

.grid-content {
    display: flex;
    align-items: center;
    height: 100px;
}

.grid-cont-right {
    flex: 1;
    text-align: center;
    font-size: 14px;
    color: #999;
}

.grid-num {
    font-size: 30px;
    font-weight: bold;
}

.grid-con-icon {
    font-size: 50px;
    width: 100px;
    height: 100px;
    text-align: center;
    line-height: 100px;
    color: #fff;
}

.grid-con-1 .grid-con-icon {
    background: rgb(45, 140, 240);
}

.grid-con-1 .grid-num {
    color: rgb(45, 140, 240);
}

.grid-con-2 .grid-con-icon {
    background: rgb(100, 213, 114);
}

.grid-con-2 .grid-num {
    color: rgb(45, 140, 240);
}

.grid-con-3 .grid-con-icon {
    background: rgb(242, 94, 67);
}

.grid-con-3 .grid-num {
    color: rgb(242, 94, 67);
}

.user-info {
    display: flex;
    align-items: center;
    padding-bottom: 20px;
    border-bottom: 2px solid #ccc;
    margin-bottom: 20px;
}

.user-avator {
    width: 120px;
    height: 120px;
    border-radius: 50%;
}

.user-info-cont {
    padding-left: 50px;
    flex: 1;
    font-size: 14px;
    color: #999;
}

.user-info-cont div:first-child {
    font-size: 30px;
    color: #222;
}

.user-info-list {
    font-size: 14px;
    color: #999;
    line-height: 25px;
}

.user-info-list span {
    margin-left: 70px;
}

.mgb20 {
    margin-bottom: 20px;
}

.todo-item {
    font-size: 14px;
}

.todo-item-del {
    text-decoration: line-through;
    color: #999;
}

.schart {
    width: 100%;
    height: 300px;
}
.el-carousel__item h3 {
    color: #475669;
    font-size: 18px;
    opacity: 0.75;
    line-height: 300px;
    margin: 0;
}

.el-carousel__item:nth-child(2n) {
    background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n+1) {
    background-color: #d3dce6;
}
</style>
